package com.tyto.training;

import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Random;

public class SampleLogging {
	private final static Logger LOGGER = Logger.getLogger(SampleLogging.class
			.getName());

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner userInput = new Scanner(System.in);
		String firstNumberString = null;
		int firstNumber = 0;
		while (firstNumberString == null) {			
			System.out.print("Enter your first number: ");
			firstNumberString = userInput.next();
			LOGGER.info("User entered first number : [" + firstNumberString + "]");
			try {
				firstNumber = Integer.parseInt(firstNumberString);
			} catch (NumberFormatException nfe) {
				LOGGER.log(Level.WARNING, "User entered an invalid number : [" + firstNumberString + "]", nfe);
				firstNumberString = null;
			}
		}
		Random randomGenerator = new Random();
		int randomInt = randomGenerator.nextInt(100);
		LOGGER.info("System generated : [" + randomInt + "]");
		double average = Math.sqrt(firstNumber * randomInt);
		if (LOGGER.isLoggable(Level.FINER)) {
			LOGGER.finer("Calculated average is : [" + average + "]");
		}
	}

}
